package com.newbingo.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.newbingo.dao.PeriodGameDao;
import com.newbingo.dao.imple.IPeriodGameDao;
import com.newbingo.dto.imple.IPeriodHistoryDto;
import com.newbingo.entity.BettingCell;
import com.newbingo.entity.GamePlay;
import com.newbingo.entity.Lottery;
import com.newbingo.entity.PeriodGame;
import com.newbingo.entity.PeriodGameResult;
import com.newbingo.util.Pager;

public class PeriodHistoryDto  implements IPeriodHistoryDto,Serializable{

	private Integer gtno;        // 游戏桌Id
	private String periodTime;   // 开奖时间
	private String periodNum;    // 游戏期号
	private String gamename;     // 游戏名称
	private String tablename;    // 游戏桌名称
	private String lotteryNum="";   // 开奖号码
	private String winCell="";    //中奖投注格
	private Integer sum=0;
	private  IPeriodGameDao periodDao=null;
	
	
	//将PeriodGame转换成DTO对象
	public  Pager changeToString(int start,int limit,int gtno,String date){
		System.out.println(start+limit+""+gtno+date);
		Pager page=periodDao.findHistoryRecord(start, limit, gtno, date);
		List<PeriodGame> list=page.getData();
		List<PeriodHistoryDto> phd=new ArrayList<PeriodHistoryDto>();
		//定义返回Pager对象
		Pager pager=new Pager();
		pager.setTotalSize(page.getTotalSize());
		PeriodHistoryDto dto=null;
		if(list!=null && list.size()>0){
			for (PeriodGame period : list) {
				dto=new PeriodHistoryDto();
				dto.setGtno(period.getGameTable().getGtno());
				if(period.getPeriodTime()!=null)
					dto.setPeriodTime(period.getPeriodTime().toString());
				dto.setPeriodNum(period.getPgnum()+"");
				dto.setTablename(period.getGameTable().getName());
				dto.setGamename(period.getGameTable().getGame().getGamename());
				List<Lottery> result=period.getPeriodGameResult().getLotteries();
				//循环获取中奖的号码
				if(result!=null && result.size()>0){
					for (Lottery lottery : result) {
//						System.out.println("Lottery的数值："+lottery.getNum());
						dto.setSum(dto.getSum()+lottery.getNum());
						dto.setLotteryNum(dto.getLotteryNum()+"&nbsp;"+lottery.getNum());
					}
				}
				//循环获取中奖的投注格
				Set<BettingCell> cells=period.getPeriodGameResult().getCells();
				if(cells!=null && cells.size()>0){
					for(BettingCell bc:cells)
						dto.setWinCell(dto.getWinCell()+"&nbsp;"+bc.getName());
				}
				System.out.println(dto.getWinCell());
				phd.add(dto);
			}
		}
		 pager.setData(phd);
		return pager;
	}
		

	//默认无参构造函数
	public PeriodHistoryDto(){
		
	}
	
//	带参构造函数
//	public PeriodHistoryDto(Integer gtno,String periodTime,String periodNum,String gamename,String tablename,String lotteryNum){
//		this.gtno=gtno;
//		this.periodTime=periodTime;
//		this.periodNum=periodNum;
//		this.gamename=gamename;
//		this.tablename=tablename;
//		this.lotteryNum=lotteryNum;
//	}
//	
	
	public Integer getGtno() {
		return gtno;
	}

	public void setGtno(Integer gtno) {
		this.gtno = gtno;
	}

	public String getPeriodTime() {
		return periodTime;
	}

	public void setPeriodTime(String periodTime) {
		this.periodTime = periodTime;
	}

	public String getPeriodNum() {
		return periodNum;
	}

	public void setPeriodNum(String periodNum) {
		this.periodNum = periodNum;
	}

	public String getGamename() {
		return gamename;
	}

	public void setGamename(String gamename) {
		this.gamename = gamename;
	}

	public String getTablename() {
		return tablename;
	}

	public void setTablename(String tablename) {
		this.tablename = tablename;
	}

	public String getLotteryNum() {
		return lotteryNum;
	}

	public void setLotteryNum(String lotteryNum) {
		this.lotteryNum = lotteryNum;
	}
	public IPeriodGameDao getPeriodDao() {
		return periodDao;
	}
	public void setPeriodDao(IPeriodGameDao periodDao) {
		this.periodDao = periodDao;
	}


	public String getWinCell() {
		return winCell;
	}


	public void setWinCell(String winCell) {
		this.winCell = winCell;
	}


	public Integer getSum() {
		return sum;
	}


	public void setSum(Integer sum) {
		this.sum = sum;
	}
	
}
